package com.li.search;

class binarySerach {
    public static void main(String[] args) {
        int arr[] = {1, 5, 9, 25, 36, 37, 59};
        System.out.println(binary(arr, 0, arr.length - 1, 4));

    }

    public static int binary(int[] arr, int left, int right, int finVal) {
        int mid = (left + right) / 2;
        int midval = arr[mid];
        if (left > right) {
            return -1;
        }
        if (finVal > midval) {
            return binary(arr, mid + 1, right, finVal);
        } else if (finVal < midval) {
            return binary(arr, left, mid - 1, finVal);
        } else {
            return mid;
        }
    }
}
